## [1] "Run Completed at 2018-01-31 14:42:27"

Elevation ranges

##                 Hummingbird    Low        m   High Index
## 1    White-whiskered Hermit 1340.0 1397.917 1606.4     1
## 2            Andean Emerald 1370.0 1416.417 1588.5     1
## 3    Stripe-throated Hermit 1360.0 1420.425 1640.0     1
## 4 Rufous-tailed Hummingbird 1368.5 1430.636 1690.0     1
## 5         Crowned Woodnymph 1343.5 1466.714 2300.0     1
## 6  Wedge-billed Hummingbird 1331.0 1616.850 2038.5     3

What elevation transect is each observation in? The camera data need to be inferred from the GPS point.

Summarize daily interactions

To estimate the daily detectability, there can only be a max of one interaction per day. We use mean elevation to average across observations within a transect

Static betadiversity

Modeling Fitting

Random Baseline

\[ Yobs_{i,j} \sim Bernoulli(\lambda_{i,j}) \]

## sink("models/SpeciesIdentity.jags")
## cat("
##     model {
##     
##     for (x in 1:Nobs){
## 
##     #observation
##     logit(s[x])<-alpha[Bird[x],Plant[x]]
##     Yobs[x] ~ dbern(s[x])
##     
##     #Observed discrepancy
##     E[x]<-abs(Yobs[x]- s[x])/Nobs
##     }
##     
##     #Assess Model Fit - Predict remaining data
##     for(x in 1:Nnewdata){
##     
##       #Generate prediction
##       logit(snew[x])<-alpha[NewBird[x],NewPlant[x]]
##       Ynew_pred[x]~dbern(snew[x])
##     
##       #Assess fit, proportion of corrected predicted observations
##       E.new[x]<-abs(Ynew[x]-Ynew_pred[x])/Nnewdata
## 
##     }
##     
##     #Priors
## 
##     #Species level priors
##     for (i in 1:Birds){
##       for (j in 1:Plants){
## 
##         #Intercept
##         #logit prior, then transform for plotting
##         alpha[i,j] ~ dnorm(0,0.386)
##       } 
##     }
## 
##     #derived posterior check
##     fit<-sum(E[]) #Discrepancy for the observed data
##     fitnew<-sum(E.new[])
##     }
##     ",fill=TRUE)
## 
## sink()

Predicted

## Compiling model graph
##    Resolving undeclared variables
##    Allocating nodes
## Graph information:
##    Observed stochastic nodes: 0
##    Unobserved stochastic nodes: 7096
##    Total graph size: 41908
## 
## Initializing model

Assess Convergence

Species Identity

\[ Yobs_{i,j} \sim Bernoulli(\lambda_{i,j}) \]

## sink("models/SpeciesIdentity.jags")
## cat("
##     model {
##     
##     for (x in 1:Nobs){
## 
##     #observation
##     logit(s[x])<-alpha[Bird[x],Plant[x]]
##     Yobs[x] ~ dbern(s[x])
##     
##     #Observed discrepancy
##     E[x]<-abs(Yobs[x]- s[x])/Nobs
##     }
##     
##     #Assess Model Fit - Predict remaining data
##     for(x in 1:Nnewdata){
##     
##       #Generate prediction
##       logit(snew[x])<-alpha[NewBird[x],NewPlant[x]]
##       Ynew_pred[x]~dbern(snew[x])
##     
##       #Assess fit, proportion of corrected predicted observations
##       E.new[x]<-abs(Ynew[x]-Ynew_pred[x])/Nnewdata
## 
##     }
##     
##     #Priors
## 
##     #Species level priors
##     for (i in 1:Birds){
##       for (j in 1:Plants){
## 
##         #Intercept
##         #logit prior, then transform for plotting
##         alpha[i,j] ~ dnorm(0,0.386)
##       } 
##     }
## 
##     #derived posterior check
##     fit<-sum(E[]) #Discrepancy for the observed data
##     fitnew<-sum(E.new[])
##     }
##     ",fill=TRUE)
## 
## sink()

Predicted

## Compiling model graph
##    Resolving undeclared variables
##    Allocating nodes
## Graph information:
##    Observed stochastic nodes: 3680
##    Unobserved stochastic nodes: 3416
##    Total graph size: 33145
## 
## Initializing model

Assess Convergence

Trait-matching

For hummingbird species i feeding on plant species j observed at time k and sampling event observed by transect

Observation Model:

\[ Yobs_{i,j,k,d} \sim Binomial(N_{i,j,k},\omega) \]

Process Model:

\[ N_{i,j,k} \sim Binomial(\lambda_{i,j,k}) \] \[ logit(\lambda_{i,j,k}) = \alpha_i + \beta_{1,i} * Traitmatch_{i,j} \]

## sink("models/TraitMatch.jags")
## cat("
##     model {
##     
##     #Observation Model
##     for (x in 1:Nobs){
##     
##     #Observation Process
##     #True state
##     z[x] ~ dbern(detect[Bird[x]]) 
##     
##     #observation
##     logit(s[x])<-alpha[Bird[x]] + beta1[Bird[x]] * Traitmatch[Bird[x],Plant[x]] 
##     p[x]<-z[x] * s[x]
##     Yobs[x] ~ dbern(p[x])
##     
##     #Observed discrepancy
##     E[x]<-abs(Yobs[x]- s[x])
##     }
##     
##     #Assess Model Fit - Predict remaining data
##     for(x in 1:Nnewdata){
##     
##     #Generate prediction
##     znew[x] ~ dbern(detect[NewBird[x]])
##     logit(snew[x])<-alpha[NewBird[x]] + beta1[NewBird[x]] * Traitmatch[NewBird[x],NewPlant[x]] 
##     pnew[x]<-znew[x]*snew[x]
##     Ynew_pred[x]~dbern(pnew[x])
##     
##     #Assess fit, proportion of corrected predicted links
##     E.new[x]<-abs(Ynew[x]-Ynew_pred[x])/Nnewdata
##     
##     }
##     
##     #Priors
##     #Observation model
##     #Detect priors, logit transformed - Following lunn 2012 p85
##     
##     for(x in 1:Birds){
##     logit(detect[x])<-dcam[x]
##     dcam[x]~dnorm(omega_mu,omega_tau)
##     }
##     
##     #Process Model
##     #Species level priors
##     for (i in 1:Birds){
##     
##     #Intercept
##     #logit prior, then transform for plotting
##     alpha[i] ~ dnorm(alpha_mu,alpha_tau)
##     
##     #Traits slope 
##     beta1[i] ~ dnorm(beta1_mu,beta1_tau)    
##     
##     }
##     
##     #OBSERVATION PRIOR
##     omega_mu ~ dnorm(0,0.386)
##     omega_tau ~ dunif(0,10)
##     
##     #Group process priors
##     
##     #Intercept 
##     alpha_mu ~ dnorm(0,0.386)
##     alpha_tau ~ dt(0,1,1)I(0,)
##     alpha_sigma<-pow(1/alpha_tau,0.5) 
##     
##     #Trait
##     beta1_mu~dnorm(0,0.386)
##     beta1_tau ~ dt(0,1,1)I(0,)
##     beta1_sigma<-pow(1/beta1_tau,0.5)
##     
##     #derived posterior check
##     fit<-sum(E[]) #Discrepancy for the observed data
##     fitnew<-sum(E.new[])
##     
##     }
##     ",fill=TRUE)
## 
## sink()
## Compiling model graph
##    Resolving undeclared variables
##    Allocating nodes
## Graph information:
##    Observed stochastic nodes: 3680
##    Unobserved stochastic nodes: 9018
##    Total graph size: 46277
## 
## Initializing model

Assess Convergence

Model Comparison

Network statistics

Predicted betadiversity

From Poisot 2016 “Network Comparison”

Dissimilairty in interactions(Beta_WN from Poisot 2012)